use std::{
    fs::{self, File},
    io::{self, Read},
};

struct User {
    first_name: String,
    last_name: String,
}

fn get_initials(user: &User) -> String {
    let first_initial = user.first_name.chars().nth(0).unwrap();
    let last_initial = user.last_name.chars().nth(0).unwrap();
    format!("{}{}", first_initial, last_initial)
}

fn main() {
    // let file = File::open("hello.txt");
    // let file = match file {
    //     Ok(file) => file,
    //     Err(error) => panic!("Problem opening the file: {:?}", error),
    // };
    // let file = file.unwrap();
    // let file = file.expect("Problem opening the file");
    let contents = read_file("hello.txt");
}

fn read_file(filename: &str) -> Result<String, io::Error> {
    let mut file = File::open(filename)?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;
    Ok(contents)
}

fn read_first_line(filename: &str) -> Option<String> {
    fs::read_to_string(filename)
        .ok()
        .and_then(|s| s.lines().next().map(|s| s.to_string()))
}
